import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:music_app/theme/app_colors.dart';

class SearchView extends StatefulWidget {
  const SearchView({super.key});

  @override
  State<SearchView> createState() => _SearchViewState();
}

class _SearchViewState extends State<SearchView> {
  final _searchController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          onPressed: () {
            Get.back();
          },
          icon: const Icon(
            Icons.arrow_back,
            size: 24,
          ),
        ),
        title: Container(
          height: 38,
          padding: const EdgeInsets.only(left: 12, right: 12),
          decoration: BoxDecoration(
            color: AppColors.twobg,
            borderRadius: BorderRadius.circular(20),
          ),
          child: Row(
            children: [
              const Icon(
                Icons.search,
                color: AppColors.searchTextColor,
                size: 20,
              ),
              const SizedBox(
                width: 12,
              ),
              Expanded(
                child: SizedBox(
                  height: 38,
                  child: TextFormField(
                    controller: _searchController,
                    decoration: const InputDecoration(
                      hintText: '赵雷',
                      hintStyle: TextStyle(
                        color: AppColors.searchTextColor,
                        fontSize: 12,
                        height: 1.0,
                      ),
                      contentPadding: EdgeInsets.only(top: 14, bottom: 14),
                      border: InputBorder.none,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        actions: [
          GestureDetector(
            onTap: () {},
            child: Container(
              width: 30,
              height: 30,
              margin: const EdgeInsets.only(left: 12, right: 12),
              child: const Center(
                child: Text(
                  '搜索',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 14,
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
      body: Column(
        children: [
          // 浮动区域
          _buildTabs(),
          // 滚动区域
          _buildContainer(),
        ],
      ),
    );
  }

  Widget _buildContainer() {
    return Expanded(
      child: SizedBox(
        width: double.infinity,
        child: SingleChildScrollView(
          child: Column(
            children: [
              _buildSearchHistory(),
              _buildLovely(),
              _buildHotList(),
              _buildHotList(),
              _buildHotList(),
              _buildHotList(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildSearchHistory() {
    return const SizedBox(
      height: 200,
      child: Text('搜索历史'),
    );
  }

  Widget _buildLovely() {
    return const SizedBox(
      height: 200,
      child: Text('猜你喜欢'),
    );
  }

  Widget _buildHotList() {
    return const SizedBox(
      height: 200,
      child: Text('热搜榜'),
    );
  }

  Widget _buildTabs() {
    return const SizedBox(
      width: double.infinity,
      height: 56,
      child: Text('tabs'),
    );
  }
}
